import 'package:flutter/material.dart';
import 'package:flutter_project/common/route_page/route_name.dart';
import 'package:flutter_project/common/utils/screen_size_utils.dart';
import 'package:flutter_project/user/user_info/user_edit_info.dart';
import 'package:flutter_project/user/user_login/user_info_model.dart';
import '../config/theme_color.dart';
import '../config/web_page.dart';
import '../generated/l10n.dart';
import 'account_manage_page.dart';
import 'collect/permission_manage_page.dart';
import 'package:flutter_project/common/utils/extension_utils.dart';

class UserProfilePage extends StatefulWidget {
  final UserInfoRespModel infoRespModel;

  const UserProfilePage({required this.infoRespModel, super.key});

  @override
  State<UserProfilePage> createState() => _UserProfilePageState();
}

class _UserProfilePageState extends State<UserProfilePage> {
  UserInfoRespModel infoRespModel = UserInfoRespModel();

  @override
  Widget build(BuildContext context) {
    String sexStr = infoRespModel.gender == 1
        ? 'assets/images/as_avatar_man.png'
        : 'assets/images/as_avatar_woman.png';
    String privacyPolicy = S.of(context).privacyPolicy;
    String userPolicy = S.of(context).userPolicy;
    String personalInfoCollectList = S.of(context).personalInfoCollectList;
    String applyUseRight = S.of(context).applyUseRight;
    String systemRight = S.of(context).systemRight;
    String accountManage = S.of(context).accountManage;

    return Container(
      color: ThemeColor.mainBgColor,
      width: ScreenSizeUtils.deviceScreenWidth(context) * 0.7,
      child: Column(
        children: [
          GestureDetector(
            onTap: () {
              RouteNames.push(UserEditInfo(
                infoRespModel: infoRespModel,
              ));
            },
            child: Container(
              height: 131,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                    colors: [
                      const Color.fromRGBO(179, 158, 237, 0.0),
                      ThemeColor.mainBgColor
                    ],
                    tileMode: TileMode.mirror,
                    begin: Alignment.topCenter,
                    end: Alignment.bottomCenter),
              ),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  const SizedBox(
                    width: 16,
                  ),
                  Image.asset(
                    sexStr,
                    width: 60,
                  ),
                  const SizedBox(
                    width: 10,
                  ),
                  Column(
                    mainAxisSize: MainAxisSize.min,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        infoRespModel.nickname ?? '',
                        style: const TextStyle(
                            fontSize: 18, fontWeight: FontWeight.bold),
                      ),
                      const SizedBox(
                        height: 10,
                      ),
                      Text(
                        '用户:${infoRespModel.phoneNum!
                            .getRightPhone(infoRespModel.phoneNum ?? '')}',
                        style: TextStyle(color: ThemeColor.textColorSecond),
                      ),
                    ],
                  )
                ],
              ),
            ),
          ),
          const SizedBox(
            height: 20,
          ),
          Expanded(
            child: ListView(
              padding: const EdgeInsets.symmetric(horizontal: 0, vertical: 0),
              children: [
                const SizedBox(height: 20),
                Container(
                  padding:
                      const EdgeInsets.symmetric(horizontal: 20, vertical: 0),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(0),
                    //boxShadow: const [UX.boxShadow],
                  ),
                  child: Column(
                    children: [
                      InkWell(
                        onTap: () {
                          RouteNames.push(
                            WebPage(
                              url: 'assets/html/PrivacyPolicy.html',
                              title: privacyPolicy,
                            ),
                          );
                        },
                        child: getListItem(name: privacyPolicy),
                      ),
                      const Divider(
                        height: 1,
                        color: Color(0xffe8e8e8),
                      ),
                      InkWell(
                        onTap: () {
                          RouteNames.push(
                            WebPage(
                              url: 'assets/html/UserPolicy.html',
                              title: userPolicy,
                            ),
                          );
                        },
                        child: getListItem(name: userPolicy),
                      ),
                      const Divider(
                        height: 1,
                        color: Color(0xffe8e8e8),
                      ),
                      InkWell(
                        onTap: () {
                          RouteNames.push(
                            WebPage(
                              url: 'assets/html/PersonInfoCollect.html',
                              title: personalInfoCollectList,
                            ),
                          );
                        },
                        child: getListItem(name: personalInfoCollectList),
                      ),
                      const Divider(
                        height: 1,
                        color: Color(0xffe8e8e8),
                      ),
                      InkWell(
                        onTap: () {
                          RouteNames.push(
                            WebPage(
                              url: 'assets/html/ApplyUserRight.html',
                              title: applyUseRight,
                            ),
                          );
                        },
                        child: getListItem(name: applyUseRight),
                      ),
                      const Divider(
                        height: 1,
                        color: Color(0xffe8e8e8),
                      ),
                      InkWell(
                        onTap: () {
                          RouteNames.push(PermissionManagePage(
                            title: systemRight,
                          ));
                        },
                        child: getListItem(name: systemRight),
                      ),
                      const Divider(
                        height: 1,
                        color: Color(0xffe8e8e8),
                      ),
                      InkWell(
                        onTap: () {
                          RouteNames.push(AccountManagePage(
                            title: accountManage,
                          ));
                        },
                        child: getListItem(name: accountManage),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  Widget getListItem({
    required String name,
  }) {
    return Row(
      children: [
        Padding(
          padding: const EdgeInsets.symmetric(vertical: 16),
          child: Text(
            name,
          ),
        ),
        const Spacer(),
        Icon(
          Icons.arrow_forward_ios_rounded,
          size: 14,
          color: ThemeColor.grayB5B5B5Color,
        ),
      ],
    );
  }

  @override
  void initState() {
    super.initState();
    infoRespModel = widget.infoRespModel;
  }
}
